<template>
  <div class="login-container" @keyup.enter.native="handleLogin">
    <div class="login-info">
      <!-- <h2 class="login-info-title">种一棵树最好的时间是十年前，<br/>其次是现在……</h2> -->
    </div>
    <canvas style="position: fixed; left:0; bottom:0" id='d1' width="600" height="500"></canvas>
    <div class="login-border">
      <div class="login-main">
        <h2 class="login-title">开放实验室管理系统</h2>
        <el-tabs v-model="activeName">
          <el-tab-pane label="登录" name="login">
            <user-login/>
          </el-tab-pane>
          <el-tab-pane label="注册" name="register">
            <user-register/>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </div>
</template>

<script>

import userLogin from './userLogin'
import userRegister from './userRegister'
export default {
  name: 'login',
  data() {
    return {
      activeName: 'login'
    }
  },
  mounted() {
    // const drawtree = function(ctx, startx, starty, length, angle, depth, branchWidth) {
    //   const rand = Math.random
    //   var n_length
    //   let n_angle
    //   const maxbranch = 4
    //   const n_depth = depth - 1
    //   const maxangle = 2 * Math.PI / 4
    //   const subbranch = (rand() * (maxbranch - 1)) + 1

    //   ctx.beginPath()
    //   ctx.moveTo(startx, starty)
    //   const endx = startx + length * Math.cos(angle)
    //   const endy = starty + length * Math.sin(angle)
    //   ctx.lineCap = 'round'
    //   ctx.lineWidth = branchWidth
    //   ctx.lineTo(endx, endy)
    //   if (depth <= 2) {
    //     // 树的枝干
    //     ctx.strokeStyle = 'rgb(0,' + (((rand() * 50) + 100) >> 0) + ',0)'
    //   } else {
    //     // 树的叶子
    //     ctx.strokeStyle = 'rgb(0,' + (((rand() * 50) + 50) >> 0) + ',50,25)'
    //   }
    //   ctx.stroke()

    //   // 判断树是否结束
    //   if (!n_depth) {
    //     return
    //   }
    //   branchWidth *= 0.5
    //   for (let i = 0; i < subbranch; i++) {
    //     n_angle = angle + rand() * maxangle - maxangle * 0.5 // 角度随机生成
    //     n_length = length * (0.5 + rand() * 0.5)
    //     setTimeout(function() {
    //       drawtree(ctx, endx, endy, n_length, n_angle, n_depth, branchWidth)
    //       return
    //     }, 500)
    //   }
    // }

    // const canvas = document.getElementById('d1') // 取到convas元素
    // const ctx = canvas.getContext('2d') // 创建context对象
    // // 初始化的树
    // drawtree(ctx, 300, 470, 100, -Math.PI / 2, 12, 12)
  },
  components: {
    userLogin,
    userRegister
  },
  methods: {
    switchLogin() {
    }

  }
}

</script>
<style lang="scss">
.login-container {
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: rgba(0, 0, 0, 0.2);
  position: relative;
  min-height: 100%;
}
.login-container::before {
  z-index: -999;
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-image: url('/static/img/login.png');
  background-size: cover;
}
.login-info {
  padding-left: 60px;
}
.login-info-title {
  line-height: 90px;
  color: #fff;
}
.login-info-item {
  font-size: 14px;
}
.login-border {
  display: flex;
  width: 450px;
  justify-content: center;
  flex-direction: column;
  padding: 30px 50px 25px 50px;
  background-color: #fff;
  border-radius: 6px;
  box-shadow: 1px 1px 2px #eee;
}
.login-main {
  border-radius: 3px;
  box-sizing: border-box;
  background-color: #fff;
}
.login-main > h3 {
  margin-bottom: 20px;
}
.login-main > p {
  color: #76838f;
}
.login-title {
  margin: 0 0 30px;
  text-align: center;
  color: #409eff;
  letter-spacing: 3px;
}
.login-submit {
  margin-top: 20px;
  width: 100%;
  border-radius: 28px;
}
.login-form {
  margin: 10px 0;
  .el-form-item__content {
    width: 270px;
  }

  .el-input {
    input {
      text-indent: 5px;
      border-color: #dcdcdc;
      border-radius: 3px;
    }
    .el-input__prefix {
      i {
        padding: 0 5px;
        font-size: 16px !important;
      }
    }
  }
}
.login-code {
  display: flex;
  align-items: center;
  justify-content: space-around;
  margin: 0 0 0 10px;
}
.login-code-img {
  margin-top: 2px;
  width: 100px;
  height: 32px;
  background-color: #fdfdfd;
  border: 1px solid #f0f0f0;
  color: #333;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 5px;
  line-height: 32px;
  text-indent: 5px;
  text-align: center;
}
.one-line {
	white-spacing:nowrap;
	float: left;
}
</style>
